let href = decodeURI(location.href);
console.log(href);
let productId = href.split('?')[1].split('&')[0].split('=')[1];
console.log(productId);
let categoryId = href.split('?')[1].split('&')[1].split('=')[1];



fetch('http://chst.vip:1234/api/getproduct?productid='+productId)
.then(function(a){
    return a.json()
})
.then(function(b){
    console.log(b);
    let str= '';
    b.result.forEach(item => {
        str +=`<div class="top">
                    ${item.productImg}
                    <p>
                        ${item.productName}
                    </p>
                </div>`
    
    });
    $('main').prepend(str);
})
.then(function(){
    fetch('http://chst.vip:1234/api/getcategorybyid?categoryid='+categoryId)
    .then(function(c){
        return c.json();
    })
    .then(function(b){
        console.log(b);
        let str = '';
        b.result.forEach(item => {
            str +=`<a href="./电商首页.html">首页></a><a href="./category.html">全部分类</a>>${item.category}>`
        });
        $('section .left').html(str);
    })
})

fetch('http://chst.vip:1234/api/getproductcom?productid='+productId)
.then(function(a){
    return a.json();
}).then(function(b){
    console.log(b);
    let str = '';
    b.result.forEach(item=>{
        str +=`<li>
                    <p class="one">
                        <span>
                            ${item.comName}
                        </span>
                        <span>
                            ${item.comTime}
                        </span>
                    </p>
                    <p class="two">
                        ${item.comContent}
                    </p>
                    <p class="three">
                       ${item.comFrom}
                    </p>
                </li>`
    })
    $('main .bottom ul').html(str)
})